<?php

/**
 * Extended HTML based View with PHP templates
 *
 * Provides interfaces to decotrate the content with outer template.
 *
 * @package Rapide_View
 *
 */
class Rapide_View_Html_Extended extends Rapide_View_Html implements Rapide_View_Interface
{
	/**
	 * Outer template's name
	 *
	 */
	const MAIN_TEMPLATE = 'Main';

	/**
	 * Attribute for content
	 *
	 */
	const CONTENTS_ATTRIBUTE = 'contents';

	private
		$_sMainTemplate = self::MAIN_TEMPLATE;

	/**
	 * Set main template
	 *
	 * View will use this template to decorate the content.
	 * 
	 * @param string $sTemplate
	 */
	public function setMainTemplate($sTemplate)
	{
		$this->_sMainTemplate = $sTemplate;
	}

	/**
	 * Render and get the content of view
	 *
	 * @return string content
	 */
	public function fetch()
	{
		if(!isset($this->_sTemplate))
		{
			$sError = 'Template has not been set';
			throw new Rapide_View_Html_Exception($sError);
		}

		ob_start();

		require $this->_getTemplateFile($this->_sTemplate);

		$sContents = ob_get_clean();

		$sContentsAttribute = self::CONTENTS_ATTRIBUTE;
		$this->$sContentsAttribute = $sContents;

		ob_start();

		require $this->_getTemplateFile($this->_sMainTemplate);

		$sContents = ob_get_clean();

		return $sContents;
	}
}

?>